﻿using System.Data.Objects.DataClasses;

namespace WmsApp.Service
{
    /// <summary>
    /// 此class有重构的必要，因为工厂只需要传入接口就行，无需传入实现类，这样就违背了“对接口编程”的宗旨，
    /// 且可维护性比较差，解决方案是，将接口和实现类分别注入IoC中，预先配置好。
    /// </summary>
    public class EntityServiceFactory
    {
        public static IEntityService<T, TK> GetEntityService<T, TK>() 
            where T : EntityObject  
            where TK: IEntityService<T, TK>
        {
            object instance = typeof (TK).Assembly.CreateInstance(typeof (TK).ToString());
            return instance as IEntityService<T, TK>;
        }

        public static IWrapService<T> GetWrapService<T,TK>()
              where TK : IWrapService<T>
        {
            object instance = typeof(TK).Assembly.CreateInstance(typeof(TK).ToString());
            return instance as IWrapService<T> ;
        }
    }
}
